export class YVector2 {
  public x: number;
  public y: number;

  constructor(x = 0, y = 0) {
    this.x = x;
    this.y = y;
  }

  get width() {
    return this.x;
  }

  set width(value) {
    this.x = value;
  }
  get height() {
    return this.y;
  }

  set height(value) {
    this.y = value;
  }

  set(x: number, y: number): this {
    this.x = x;
    this.y = y;
    return this;
  }

  setScalar(scalar: number): this {
    this.x = scalar;
    this.y = scalar;
    return this;
  }

  setX(x: number): this {
    this.x = x;
    return this;
  }

  setY(y: number): this {
    this.y = y;
    return this;
  }

  setComponent(index: number, value: number): this {
    switch (index) {
      case 0:
        this.x = value;
        break;
      case 1:
        this.y = value;
        break;
      default:
        throw new Error("index is out of range: " + index);
    }
    return this;
  }

  getComponent(index: number) {
    switch (index) {
      case 0:
        return this.x;
      case 1:
        return this.y;
      default:
        throw new Error("index is out of range: " + index);
    }
  }

  clone(): YVector2 {
    return new YVector2(this.x, this.y);
  }

  copy(v: YVector2): this {
    this.x = v.x;
    this.y = v.y;
    return this;
  }
  add(v: YVector2, w: YVector2): this {
    if (w !== undefined) {
      console.warn(
        "THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead."
      );
      return this.addVectors(v, w);
    }

    this.x += v.x;
    this.y += v.y;

    return this;
  }
  addScalar(s: number) {
    this.x += s;
    this.y += s;

    return this;
  }

  addVectors(a: YVector2, b: YVector2) {
    this.x = a.x + b.x;
    this.y = a.y + b.y;

    return this;
  }
	addScaledVector( v: { x: number; y: number; }, s: number ) {

		this.x += v.x * s;
		this.y += v.y * s;

		return this;

	}

	sub( v: { x: number; y: number; }, w: undefined ) {

		if ( w !== undefined ) {

			console.warn( 'THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
			return this.subVectors( v, w );

		}

		this.x -= v.x;
		this.y -= v.y;

		return this;

	}

	subScalar( s: number ) {

		this.x -= s;
		this.y -= s;

		return this;

	}

	subVectors( a: { x: number; y: number; }, b: { x: number; y: number; } ) {

		this.x = a.x - b.x;
		this.y = a.y - b.y;

		return this;

	}

	multiply( v: { x: number; y: number; } ) {

		this.x *= v.x;
		this.y *= v.y;

		return this;

	}

	multiplyScalar( scalar: number ) {

		this.x *= scalar;
		this.y *= scalar;

		return this;

	}

	divide( v: { x: number; y: number; } ) {

		this.x /= v.x;
		this.y /= v.y;

		return this;

	}

	divideScalar( scalar: number ) {

		return this.multiplyScalar( 1 / scalar );

	}

}
